﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace The_LarX
{
    public class Node_DeleteActor : VisualScript_Node, IVisualScriptNode_NeedObject
    {
        public List<VisualScript_Node> Objects { get; set; }

        public Node_DeleteActor(VisualScript vs)
            : base(vs)
        {
            this.RepresentationType = typeof(VSR_ObjectNeeded);
            Objects = new List<VisualScript_Node>();
            Load();
        }

        public Node_DeleteActor()
        {
            this.RepresentationType = typeof(VSR_ObjectNeeded);
            Load();
        }

        private void Load()
        {
            this.descriptionName = "Actor Remover";
        }

        public override void Draw()
        {
            if (AllConditionsAllow())
            {
                base.Draw();

                for (int i = 0; i < Objects.Count; i++)
                {
                    if (Objects[i] is IVisualScriptNode_Object)
                    {
                        IVisualScriptNode_Object obj = Objects[i] as IVisualScriptNode_Object;
                        if (obj.Object is Actor)
                        {
                            Actor actor = obj.Object as Actor;
                            actor.RemoveActorFromRenderer(actor);
                            actor.Disable();
                        }
                    }
                }
            }
        }

        public override void SerializeData(SerializeData Data)
        {
            base.SerializeData(Data);

            Data.AddData(CreatedNumber + "Objects", NodesToStringWithNames(Objects));
        }
        public override void DeserializeData(SerializeData Data)
        {
            base.DeserializeData(Data);

            this.Objects = StringWithNamesToNodes(Data.GetData<string>(CreatedNumber + "Objects"), Script);
        }
    }
}
